package com.xjm.bean.beanfactory;

import com.xjm.bean.imports.NeedImportBean;
import com.xjm.bean.init.ApplicationConfig;
import com.xjm.model.Person;
import com.xjm.model.PersonFactoryBean;
import com.xjm.service.HelloService;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * @author jaymin
 * 2020/11/30 20:12
 */
@SuppressWarnings("all")
public class BeanFactoryDemo {
	public static void main(String[] args) throws Exception {
		AnnotationConfigApplicationContext applicationContext = ApplicationConfig.getApplicationContext();
		HelloService helloService = applicationContext.getBean(HelloService.class);
		System.out.println(helloService.hello());
/*		NeedImportBean needImportBean = applicationContext.getBean(NeedImportBean.class);
		needImportBean.doSomething();*/
		Person bean = (Person) applicationContext.getBean("person", "Jack", 18);
		System.out.println(bean.toString());
		getPerson(applicationContext);
	}

	private static void getPerson(AnnotationConfigApplicationContext applicationContext) throws Exception {
		Person person = (Person) applicationContext.getBean("person", "Jack");
		PersonFactoryBean factoryBean = (PersonFactoryBean) applicationContext.getBean("&personFactoryBean");
		Person personB = factoryBean.getObject();
		personB.setName("The Bean Created By FactoryBean");
		System.out.println(personB.toString());
	}
}
